/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.mleiria.app.web.bean;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import pt.mleiria.bo.dashboard.AlertsEJB;
import pt.mleiria.vo.AlertVO;
import pt.mleiria.vo.Constants;
import pt.mleiria.vo.DayOfWeek;
import pt.mleiria.vo.UtilsVO;

/**
 *
 * @author manuel
 */
@ManagedBean(name = "alertsBean")
@SessionScoped
public class AlertsBean extends MasterBean{
    
    @EJB
    private AlertsEJB alertsEjb;
    /**
     * 
     * @return 
     */
    public AlertsEJB getAlertsEjb() {
        return alertsEjb;
    }
    
    public AlertVO[] getAlerts(){
        if(isFilter)
            return alerts;
        else
            return alertsEjb.getAllAlerts();
    }
    private String nome;
    public String[] nomes;
    private String diaSemana;
    private String[] diasSemana;
    private boolean isFilter;
    public AlertVO[] alerts;
    public String[] allDiasSemana;
    public String[] allNames;

    public void filterAlerts(){
        isFilter = true;
        alerts = alertsEjb.getFilterAlerts(nome, diaSemana);
    }
    public void todayAlerts(){
        isFilter = true;
        DayOfWeek dow = new DayOfWeek();
        getLogger(AlertsBean.class).info(dow.getCurrentDayOfWeek());
        alerts = alertsEjb.getFilterAlerts(Constants.TODOS, dow.getCurrentDayOfWeek());
    }   
    public void tomorrowAlerts(){
        isFilter = true;
        DayOfWeek dow = new DayOfWeek();
        alerts = alertsEjb.getFilterAlerts(Constants.TODOS, dow.getCurrentDayOfWeekPlusOne());
    }
    public void eraseAlert(final AlertVO a){
        alertsEjb.deleteAlert(a.getId());
        getLogger(AlertsBean.class).info("Delete:" + a.getId());
    }
    public String getDiaSemana() {
        return diaSemana;
    }

    public void setDiaSemana(String diaSemana) {
        this.diaSemana = diaSemana;
    }

    public String[] getDiasSemana() {
        diasSemana = alertsEjb.getDiasSemanaAlert();
        return UtilsVO.putTodos(diasSemana);
    }

    public void setDiasSemana(String[] diasSemana) {
        this.diasSemana = diasSemana;
    }
    
       
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String[] getNomes() {
        nomes = alertsEjb.getNomesAlert();
        return UtilsVO.putTodos(nomes);
    }

    public void setNomes(String[] nomes) {
        this.nomes = nomes;
    }
    
    public String[] getAllDiasSemana() {
        diasSemana = alertsEjb.getAllDiasSemana();
        return diasSemana;
    }

    public String[] getAllNames() {
        allNames = alertsEjb.getAllNames();
        return allNames;
    }

}
